<template>
   <div class="container">
    <el-card >
    <el-form ref="form" :model="form" :rules="rules">
  <!-- 放置Logo图片 -->
  <div class="title-container">
        <h3 class="title">
          <img src="@/assets/极客园.png" alt="" class="logopc">
        </h3>
      </div>

        <el-form-item prop="mobile">
          <el-input v-model="form.mobile" placeholder="请输入手机号"></el-input>
        </el-form-item>
        <el-form-item prop="code">
        <el-input  v-model="form.code" placeholder="请输入验证码"></el-input>
        </el-form-item>
        <el-form-item>
          <el-checkbox :value="true">我已阅读并同意「用户协议」和「隐私条款」</el-checkbox>
        </el-form-item>
        <el-form-item>
          <el-button @click="login()" type="primary">登录</el-button>
        </el-form-item>
      </el-form>
    </el-card>
   </div>
</template>

<script>
export default {
  name: 'LoginIndex',
  data () {
    return {
      // 数据
      form: {
        mobile: '13200000000',
        code: '246810'
      },
      // 规则
      rules: {
        mobile: [
          { required: true, message: '请输入手机号', trigger: 'blur' },
          { pattern: /^1[3-9]\d{9}$/, trigger: 'blur', message: '手机号格式不正确' }
        ],
        code: [
          { required: true, message: '请输入验证码', trigger: 'blur' },
          { len: 6, message: '验证码6个字符', trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    login () {
      this.$refs.form.validate(async valid => {
        if (valid) {
          try {
            // 请求
            const res = await this.$http.post('/v1_0/authorizations', this.form)
            // 成功
            localStorage.setItem('geek-client-pc-store', res.data.data.token)
            this.$router.push('/')
          } catch (e) {
          // 失败
            this.$message.error(e.response.data.message || '登录失败')
          }
        }
      })
    }
  }
}
</script>

<style scoped lang="less">
.container{
  .el-card {
    width: 440px;
    height: 380px;
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%,-50%);
    box-shadow: 0 0 50px rgba(0,0,0,0.1);
  }
  .el-form {
      padding: 0 20px;
      .el-form-item{
        // padding-top: 20px;
      }
      .el-button {
        width: 100%;
      }
    }
   .title-container {
    position: relative;

    .title {
      .logopc{
      width: 200px;
      display: block;
    margin: 0 auto 20px;
    background-color: #fff;

     }
    }
  }

}

</style>
